package com.ktgj.other.service.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.ktgj.common.core.annotation.Excel;
import com.ktgj.other.domain.vo.TicketsDateVo;
import com.ktgj.other.domain.vo.WriteOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktgj.other.mapper.EtSceneryticketCalendarMapper;
import com.ktgj.other.domain.EtSceneryticketCalendar;
import com.ktgj.other.service.IEtSceneryticketCalendarService;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-07-22
 */
@Service
public class EtSceneryticketCalendarServiceImpl implements IEtSceneryticketCalendarService 
{
    @Autowired
    private EtSceneryticketCalendarMapper etSceneryticketCalendarMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param pricecalendarid 【请填写功能名称】ID
     * @return 【请填写功能名称】
     */
    @Override
    public EtSceneryticketCalendar selectEtSceneryticketCalendarById(Long pricecalendarid)
    {
        return etSceneryticketCalendarMapper.selectEtSceneryticketCalendarById(pricecalendarid);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param etSceneryticketCalendar 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<EtSceneryticketCalendar> selectEtSceneryticketCalendarList(EtSceneryticketCalendar etSceneryticketCalendar)
    {
        return etSceneryticketCalendarMapper.selectEtSceneryticketCalendarList(etSceneryticketCalendar);
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param etSceneryticketCalendar 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertEtSceneryticketCalendar(EtSceneryticketCalendar etSceneryticketCalendar)
    {
        return etSceneryticketCalendarMapper.insertEtSceneryticketCalendar(etSceneryticketCalendar);
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param etSceneryticketCalendar 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateEtSceneryticketCalendar(EtSceneryticketCalendar etSceneryticketCalendar)
    {
        return etSceneryticketCalendarMapper.updateEtSceneryticketCalendar(etSceneryticketCalendar);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param pricecalendarids 需要删除的【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteEtSceneryticketCalendarByIds(Long[] pricecalendarids)
    {
        return etSceneryticketCalendarMapper.deleteEtSceneryticketCalendarByIds(pricecalendarids);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param pricecalendarid 【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteEtSceneryticketCalendarById(Long pricecalendarid)
    {
        return etSceneryticketCalendarMapper.deleteEtSceneryticketCalendarById(pricecalendarid);
    }

    /**
     * 门票日期列表
     * */
    @Override
    public List<TicketsDateVo> ticketsDate(Long id) {
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        String date = format.format(new Date());

        List<TicketsDateVo> ticket = new ArrayList<>();
        List<EtSceneryticketCalendar> etSceneryticketCalendarList = etSceneryticketCalendarMapper.sceneryticketCalendarList(id);
        if (etSceneryticketCalendarList != null && etSceneryticketCalendarList.size() > 0){
            for (EtSceneryticketCalendar etSceneryticketCalendar : etSceneryticketCalendarList) {
                if (etSceneryticketCalendar.getDayid() != null && etSceneryticketCalendar.getDayid() != 0){
                    if (etSceneryticketCalendar.getDayid() >= Long.valueOf(date)){
                        String calendar = etSceneryticketCalendar.getDayid().toString();
                        calendar = calendar.substring(0, 4) + "-" + calendar.substring(4, 6) + "-" + calendar.substring(6);
                        TicketsDateVo ticketsDateVo = new TicketsDateVo();
                        ticketsDateVo.setId(etSceneryticketCalendar.getPricecalendarid());
                        ticketsDateVo.setDate(calendar);
                        ticket.add(ticketsDateVo);
                    }
                }
            }
        }
        return ticket;
    }

    /**
     * 获取不同日期的票价
     * */
    @Override
    public String fare(WriteOrderVo writeOrderVo) {
        String price = null;
        EtSceneryticketCalendar etSceneryticketCalendar = etSceneryticketCalendarMapper.sceneryticketCalendar(writeOrderVo.getId(), writeOrderVo.getDateTime());
        if (etSceneryticketCalendar != null){
            price = etSceneryticketCalendar.getAgentamount().toString();
        }
        return price;
    }
}
